package com.bhs.sansonglogistics.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bhs.sansonglogistics.R;
import com.bhs.sansonglogistics.utils.MyUtils;

/**
 * 版本更新
 */
public class VersionUpdatingDialog extends Dialog implements View.OnClickListener {

    private TextView mTvVersionNumber;
    private TextView mTvExplain;
    private Button mBtnConfirm;

    public VersionUpdatingDialog(@NonNull Context context) {
        super(context, R.style.MyBottomDialogStyle);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_ersion_updating);
        //获取当前Activity所在的窗体
        Window dialogWindow = getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.CENTER);
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = MyUtils.getScreenWidth(getContext()) * 8 / 10;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(lp); //将属性设置给窗体
        setCancelable(false);
        initView();

    }

    private void initView() {
        mTvVersionNumber = findViewById(R.id.tv_version_number);
        mTvExplain = findViewById(R.id.tv_explain);
        mBtnConfirm = findViewById(R.id.btn_confirm);
        mBtnConfirm.setOnClickListener(this);
    }

    public void setData(String versions, String content) {
        mTvVersionNumber.setText(String.format("%s版本更新", versions));
        mTvExplain.setText(content);
    }

    private MyClickListener listener;

    public void setMyClickListener(@Nullable MyClickListener l) {
        this.listener = l;
    }

    @Override
    public void onClick(View view) {
        listener.onClick(view);
    }
}
